package com.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.core.pojo.User.dto.UserBlacklistDTO;
import com.core.pojo.User.entity.UserBlacklist;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserBlacklistMapper extends BaseMapper<UserBlacklist> {

    /**
     * 一次性插入或更新黑名单表
     * @param dto
     */
    @Insert("INSERT INTO user_blacklist (id, expired_count, blacklisted) " +
            "VALUES (#{userId}, #{expiredCount}, false) " +
            "ON DUPLICATE KEY UPDATE " +
            "expired_count = expired_count + VALUES(expired_count), " +
            "blacklisted = (expired_count >= 3)")
    void insertOrUpdateExpiredCount(UserBlacklistDTO dto);
}
